package com.yan.Controller;


import com.yan.pojo.User;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@RestController
//@ResponseBody  返回不是页面的时候加的  是页面不加了 加上就是返回一个json的  不加去找页面
public class ControllerAjax {


    @RequestMapping("ajax1")
    public String ajax1() {

        return "yanwencha";
    }

    @RequestMapping("ajax2")
    public void ajax12(String name, HttpServletResponse response) throws IOException {

        System.out.println("name" + name);
        if ("yan".equals(name)) {
            response.getWriter().println("true");
        } else {
            response.getWriter().println("false");
        }

    }



    @RequestMapping("ajax3")
    public List<User> adc(){
        List<User> list = new ArrayList<User>();
        list.add(new User("ss",11,"男"));
        list.add(new User("ss",11,"男"));
        list.add(new User("ss",11,"男"));
        list.add(new User("ss",11,"男"));
        return list;

    }



    @RequestMapping("ajax4")
    public String ajax4(String name,String pwd){

        String msg=null;
        if (name!=null){
            if (name.equals("name")){
                msg ="ok";

            }else {
                msg ="不ok";
            }


        }
        if (pwd!=null){
            if (pwd.equals("pwd")){
                msg ="ok pwd";
            }else {
                msg ="不ok pwd";
            }


        }



        return null;
    }



}
